package com.ciwong.epaper.modules.evaluate.ui;

import android.view.View;
import android.widget.ExpandableListView;

import com.android.volley.TimeoutError;
import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.epaper.adapter.SymbolExpandableListAdapter;
import com.ciwong.epaper.modules.epaper.dao.EpaperDao;
import com.ciwong.epaper.modules.msg.bean.SymbolsContent;
import com.ciwong.mobilelib.i.BaseCallBack;
import com.ciwong.mobilelib.ui.BaseActivity;
import com.ciwong.mobilelib.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

/*音标界面*/
public class PhoneticSymbolActivity extends BaseActivity implements View.OnClickListener, ExpandableListView.OnChildClickListener {


    private List<SymbolsContent> symbolsContents;

    private SymbolExpandableListAdapter symbolExpandableListAdapter;

    private ExpandableListView expandableListView;

    private String title;


    @Override
    protected void findViews() {
        expandableListView = (ExpandableListView) findViewById(R.id.symbol_expandableListView);
        /*expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
                Symbols symbols = symbolsContents.get(i).getSymbolsList().get(i1);
                ViedoJumpManager.jumpToSymbolVideo(R.string.go_back,PhoneticSymbolActivity.this,symbols);
                return true;
            }
        });*/
        expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                return true;
            }
        });

    }


    @Override
    protected void initEvent() {
        title = "音标专练";
        setTitleText(title);
    }

    @Override
    protected void init() {

    }

    @Override
    protected void loadData() {
        showCricleProgress();
        getSymbols();
    }


    @Override
    protected int setView() {
        return R.layout.activity_symbol;
    }


    @Override
    protected void preCreate() {
        super.preCreate();
    }


    @Override
    public void onClick(View v) {
    }


    public void getSymbols() {
        EpaperDao.getInstance().getSymbolsList(new BaseCallBack() {
            @Override
            public void failed(int errorCode, Object data) {
                dismissProgress();
                ToastUtil.INSTANCE.toastCenterError("加载失败，检查网络重新请求");
            }

            @Override
            public void failed(Object data) {
                if(data instanceof TimeoutError){
                    dismissProgress();
                    ToastUtil.INSTANCE.toastCenterError("加载失败，检查网络重新请求");
                }else {
                    dismissProgress();
                    ToastUtil.INSTANCE.toastCenterError("加载失败，请稍后再试");
                }
            }

            @Override
            public void success(Object data) {
                dismissProgress();
                if (data != null && data instanceof ArrayList) {
                    symbolsContents = (List<SymbolsContent>) data;
                    symbolExpandableListAdapter = new SymbolExpandableListAdapter(symbolsContents, PhoneticSymbolActivity.this);
                    expandableListView.setAdapter(symbolExpandableListAdapter);
                    for (int i = 0; i < symbolsContents.size(); i++) {
                        expandableListView.expandGroup(i);
                    }
                }
            }
        });
    }

    private void dismissProgress() {
        hideCricleProgress();
    }

    @Override
    public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
        return false;
    }
}
